package org.example.elastic.lite.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
import org.apache.shardingsphere.elasticjob.lite.api.listener.AbstractDistributeOnceElasticJobListener;
import org.springframework.stereotype.Component;

/**
 * elastc job 监听器
 *
 * 实现分布式任务监听器
 * 如果任务有分片，分布式监听器会在开始和结束的时候各执行一次
 *
 * @author 魏荣杰
 * @date 2022/11/11 01:53
 * @since
 * @version
 */
@Slf4j
@Component
public class DynamicElasticJobListener extends AbstractDistributeOnceElasticJobListener {

    private static final long startedTimeoutMilliseconds = 10000;
    private static final long completedTimeoutMilliseconds = 10000;


    public DynamicElasticJobListener() {
        super(startedTimeoutMilliseconds, completedTimeoutMilliseconds);
    }

    public DynamicElasticJobListener(long startedTimeoutMilliseconds, long completedTimeoutMilliseconds) {
        super(startedTimeoutMilliseconds, completedTimeoutMilliseconds);
    }

    @Override
    public void doBeforeJobExecutedAtLastStarted(ShardingContexts shardingContexts) {
        log.info("DynamicElasticJobListener doBeforeJobExecutedAtLastStarted--------------");
    }


    @Override
    public void doAfterJobExecutedAtLastCompleted(ShardingContexts shardingContexts) {
        log.info("DynamicElasticJobListener doBeforeJobExecutedAtLastStarted--------------");
    }

    @Override
    public String getType() {
        return "DynamicElasticJobListener";
    }
}
